import { NextResponse } from 'next/server';
import { importAllDataFromCsv } from '@/lib/excel-to-sqlite-importer';

export async function POST() {
  try {
    console.log('API: /api/migrate-to-sqlite now redirects to CSV import logic.');
    
    // 执行来自CSV的导入
    const importResult = await importAllDataFromCsv();
    
    if (!importResult.success) {
      return NextResponse.json({
        success: false,
        error: importResult.message
      }, { status: 500 });
    }
    
    // 适配前端期望的返回格式
    return NextResponse.json({
      success: true,
      message: importResult.message,
      data: {
        migratedCount: importResult.importedCount,
        stats: [] // 提供一个空的stats数组以避免前端出错
      }
    });
    
  } catch (error) {
    console.error('数据迁移(导入)API错误:', error);
    return NextResponse.json({
      success: false,
      error: `数据导入失败: ${error instanceof Error ? error.message : '未知错误'}`
    }, { status: 500 });
  }
} 